package validator

import "fmt"

type Error struct {
    Name string
    Err error
}

func (e Error) Error() string  {
    return e.Name + e.Err.Error()
}

// valid错误 key:表示required,in等验证类型,params表示额外参数,如 “in:1,2,3”中的“[1,2,3]”
func ValidErr(key string, params ...string) string  {
    switch key {
    case "required":
        return "为必填项"
    case "email":
        return "格式错误"
    case "numeric":
        return "为正整数"
    case "int":
        return "为整数"
    case "float":
        return "为浮点数"
    case "null":
        return "为空"
    case "alpha":
        return "应为字母"
    case "alpha_num":
        return "应为字母或数字组合"
    case "alpha_dash":
        return "应为字母,数字或特殊符号组合"
    case "alpha_normal":
        return "应为字母,数字或汉字组合"
    case "ipv4":
        return "ipv4地址格式错误"
    case "ipv6":
        return "ipv6地址格式错误"
    case "mobile":
        return "格式错误"
    case "password":
        return "必须为6-20长度的字母和数字,可包含特殊字符"
    case "between":
        return "介于"+params[0]+"和"+params[1]+"之间"
    case "in":
        return "必须在给定值"+ fmt.Sprint(params)+ "之中"
    case "length":
        return "长度应在"+params[0]+"-"+params[1]+"位"
    case "same":
        return "值不一至"
    default:
        return ""
    }
}